/*****************************************************************************
 *
 *                      HUSONG PROPRIETARY INFORMATION
 *
 *          The information contained herein is proprietary to HUSONG
 *           and shall not be reproduced or disclosed in whole or in part
 *                    or used for any design or manufacture
 *              without direct written authorization from HUSONG.
 *
 *            Copyright (c) 2015 by HUSONG.  All rights reserved.
 *
 *****************************************************************************/
package me.send.produce.client.controller;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.net.InetAddress;
import java.net.UnknownHostException;

import me.send.business.service.bean.Complain;
import me.send.business.service.bean.ReturnJsonBean;
import me.send.business.service.service.ComplainService;
import me.send.produce.client.controller.base.AuthodType;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author maxmin
 *
 * @date 2015年8月24日 上午11:32:25
 */
@Controller
@RequestMapping(value="/complain")
public class ComplainController {
	@Autowired
	ComplainService complainService;
	/**
	 * 经纪人投诉用户
	 * @param complain
	 * @param devicenumber
	 * @return
	 */
	@RequestMapping()
	@ResponseBody
	public ReturnJsonBean complain(Complain complain ,String devicenumber) {
		ReturnJsonBean rb = new ReturnJsonBean();
		try {
			complainService.complain(complain);
			rb.setCode(ReturnJsonBean.SUCCESS);
			rb.setMessage(ReturnJsonBean.SUCCESS_STR);
		} catch (Exception e) {
			saveException(AuthodType.tangjianglong.getName(), "ComplainController", "complain()", e);
			e.printStackTrace();
		}
		return rb;
	}
	
	/**
	 * 保存异常信息
	 * 
	 * @param authorName
	 * @param modelName
	 * @param functionName
	 * @param e
	 */
	@SuppressWarnings("unused")
	protected void saveException(String authorName, String modelName,
			String functionName, Exception e) {
		
		try {
			// Exception的具体说明
			ByteArrayOutputStream baos = new ByteArrayOutputStream();  
	        e.printStackTrace(new PrintStream(baos));  
	        String exception = baos.toString();  
			
	        // 获得当前的IP地址
			InetAddress addr = InetAddress.getLocalHost();
			String ip=addr.getHostAddress().toString();//获得本机IP
			
		} catch (UnknownHostException e1) {
			e1.printStackTrace();
		}
	}
}
